#include "StdAfx.h"
#include "CircuitBusEntryDisObj.h"

CCircuitBusEntryDisObj::CCircuitBusEntryDisObj(CCircuitBusEntry *pCirBusentry)
	: CCircuitUnitDisObj(pCirBusentry)
{
	m_dblLineWidth = pCirBusentry->GetLineWidth();
	m_dblColor[0] = pCirBusentry->GetColorR();
	m_dblColor[1] = pCirBusentry->GetColorG();
	m_dblColor[2] = pCirBusentry->GetColorB();
}

CCircuitBusEntryDisObj::CCircuitBusEntryDisObj(const CCircuitBusEntryDisObj *pDisObj, CCircuitBusEntry *pCirBusentry/* =NULL */)
	: CCircuitUnitDisObj(pDisObj, pCirBusentry)
{

}

CCircuitBusEntryDisObj::~CCircuitBusEntryDisObj(void)
{
}

void CCircuitBusEntryDisObj::Serialize(CArchive & ar)
{
	CCircuitUnitDisObj::Serialize(ar);
}

void CCircuitBusEntryDisObj::Display(CHoopsMap *pHoopsMap)
{
	CCircuitBusEntry *pCirBusentry = (CCircuitBusEntry *)GetEntityObj();
	if (!pCirBusentry)
	{
		return;
	}

	HC_KEY key_obj = INVALID_KEY;
	char sCirLineSeg[64];
	sprintf(sCirLineSeg, "line_%d", pCirBusentry->GetId());
	key_obj = HC_Open_Segment(sCirLineSeg);
		HC_Flush_Contents(".", "everything");

		HC_Insert_Line(pCirBusentry->GetStartPosX(), pCirBusentry->GetStartPosY(), 0.0f,
			pCirBusentry->GetEndPosX(), pCirBusentry->GetEndPosY(), 0.0f);

		HC_Set_Line_Weight(GetLineWidth());

		char szColorPattern[64];
		sprintf(szColorPattern, "lines = (r=%.2f g=%.2f b=%.2f)",
			GetColorR(), GetColorG(), GetColorB());
		HC_Set_Color(szColorPattern);
	HC_Close_Segment();

	pHoopsMap->Delete(this);
	pHoopsMap->Add(key_obj, this);
}

void CCircuitBusEntryDisObj::Transform(const CMatrix transf)
{

}

CObj *CCircuitBusEntryDisObj::Clone() const
{
	return new CCircuitBusEntryDisObj(this);
}

bool CCircuitBusEntryDisObj::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	return false;
}

eCircuitUnitType CCircuitBusEntryDisObj::GetCircuitUnitType() const
{
	return CIRCUIT_BUSENTRY_DISOBJ;
}